<!--
 * FCKeditor - The text editor for internet
 * Copyright (C) 2003 Frederico Caldeira Knabben
 *
 * Licensed under the terms of the GNU Lesser General Public License
 * (http://www.opensource.org/licenses/lgpl-license.php)
 *
 * For further information go to http://www.fredck.com/FCKeditor/ 
 * or contact fckeditor@fredck.com.
 *
 * fck_link.html: Link dialog box.
 *
 * Authors:
 *   Frederico Caldeira Knabben (fckeditor@fredck.com)
-->
<html>
	<head>
		<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
		<link rel="stylesheet" type="text/css" href="../css/fck_dialog.css">
		<script language="javascript" src="../js/dhtmled.js"></script>
		<script language="javascript">
<!--
// Get browsing configuration
var bCanBrowse = dialogArguments.config.LinkBrowser ;
var sBrowseURL = dialogArguments.config.LinkBrowserURL ;
var iBrowseWindowWidth  = dialogArguments.config.LinkBrowserWindowWidth ;
var iBrowseWindowHeight = dialogArguments.config.LinkBrowserWindowHeight ;

// Get upload configuration
var bCanUpload = dialogArguments.config.LinkUpload && dialogArguments.BrowserInfo.IsIE55OrMore ;
var sUploadURL = dialogArguments.config.LinkUploadURL ;
var iUploadWindowWidth  = dialogArguments.config.LinkUploadWindowWidth ;
var iUploadWindowHeight = dialogArguments.config.LinkUploadWindowHeight ;
var sUploadAllowedExtensions = dialogArguments.config.LinkUploadAllowedExtensions ;
var sUploadDeniedExtensions  = dialogArguments.config.LinkUploadDeniedExtensions ;

// Gets the document DOM
var oDOM = dialogArguments.objContent.DOM ;

document.write("<title>" + dialogArguments.lang["DlgLnkWindowTitle"] + "</title>") ;

function setDefaults()
{
	// First of all, translate the dialog box texts
	dialogArguments.AvailableLangs.TranslatePage(document) ;
	
	var oLink = getSelectionLink() ;

	if (oLink != null)
	{
		txtURL.value    = oLink.getAttribute("href",2) ;
//		txtURL.value    = oLink.href ;
		txtTitle.value  = oLink.title ;
		selTarget.value = oLink.target ;
	}
}

function getSelectionLink()
{
	var oParent ;
	var oRange ;
	
	if (oDOM.selection.type == "Control")
	{
		oRange = oDOM.selection.createRange() ;
		for ( i = 0 ; i < oRange.length ; i++ )
		{
			if (oRange(i).parentNode)
			{
				oParent = oRange(i).parentNode ;
				break ;
			}
		}
	}
	else
	{
		oRange  = oDOM.selection.createRange() ;
		oParent = oRange.parentElement() ;
	}

	while (oParent && oParent.nodeName != "A")
	{
		oParent = oParent.parentNode ;
	}

	if (oParent && oParent.nodeName == "A")
	{
		oDOM.selection.empty() ;
		oRange = oDOM.selection.createRange() ;
		oRange.moveToElementText( oParent ) ;
		oRange.select() ;
		
		return oParent ;
	}
	else
		return null ;
}

function ok()
{
	var sUrl = txtURL.value ;
	
	if (sUrl == "")
		dialogArguments.decCommand( DECMD_UNLINK ) ;
	else
	{
		dialogArguments.decCommand( DECMD_HYPERLINK, OLECMDEXECOPT_DONTPROMPTUSER, "javascript:void(0);/*fckeditortemplink*/" ) ;
		for (i = 0 ; i < oDOM.links.length ; i++)
		{
			if ( oDOM.links[i].href == "javascript:void(0);/*fckeditortemplink*/" )
			{
				oDOM.links[i].href = sUrl ;
				
				if (txtTitle.value == "")
					oDOM.links[i].removeAttribute("title",0) ;
				else
					oDOM.links[i].title  = txtTitle.value ;
					
				if (selTarget.value == "")
					oDOM.links[i].removeAttribute("target",0) ;
				else
					oDOM.links[i].target = selTarget.value ;
			}
		}
	}

	cancel() ;
}

// Fired when the user press the CANCEL button.
function cancel() 
{
	window.returnValue = null ;
	window.close() ;
}

// Fired when the user click in the "Sent it to the Server" button.
function uploadFile()
{
	var sFile = frmUpload.FCKeditor_File.value ;

	if (sFile == "")
	{
		alert("Please select a file to upload.") ;
		return ;
	}
	
	var sExt = sFile.match( /\.[^\.]*$/ ) ;
	sExt = sExt ? sExt[0].toLowerCase() : "." ;
		
	if ( sUploadAllowedExtensions != "" && sUploadAllowedExtensions != "*" )
	{
		if ( sUploadAllowedExtensions.indexOf( sExt ) < 0 )
		{
			alert( dialogArguments.lang["DlgLnkMsgWrongExtA"] ) ; 
			return ;
		}
	}
	
	if ( sUploadDeniedExtensions != "" )
	{
		if ( sUploadDeniedExtensions.indexOf( sExt ) >= 0 )
		{
			alert( dialogArguments.lang["DlgLnkMsgWrongExtD"] ) ; 
			return ;
		}
	}
	
	var oWindow = openNewWindow("", "UploadWindow", iUploadWindowWidth, iUploadWindowHeight) ;
	frmUpload.submit() ;
	oWindow.setImage = setImage ;
}

function browserServer()
{
	var oWindow = openNewWindow(sBrowseURL, "BrowseWindow", iBrowseWindowWidth, iBrowseWindowHeight) ;
	oWindow.setImage = setImage ;
}

function openNewWindow(sURL, sName, iWidth, iHeight, bResizable, bScrollbars)
{
	var iTop  = (screen.height - iHeight) / 2 ;
	var iLeft = (screen.width  - iWidth) / 2 ;
	
	var sOptions = "toolbar=no" ;
	sOptions += ",width=" + iWidth ; 
	sOptions += ",height=" + iHeight ;
	sOptions += ",resizable="  + (bResizable  ? "yes" : "no") ;
	sOptions += ",scrollbars=" + (bScrollbars ? "yes" : "no") ;
	sOptions += ",left=" + iLeft ;
	sOptions += ",top=" + iTop ;
	
	var oWindow = window.open(sURL, sName, sOptions)
	oWindow.focus();
	
	return oWindow ;
}

function setImage(sImageURL)
{
	txtURL.value = sImageURL ;
}
//-->
		</script>
	</head>
	<body bottommargin="5" leftmargin="5" topmargin="5" rightmargin="5" onload="setDefaults()">
		<table cellspacing="1" cellpadding="1" border="0" width="100%" class="dlg" height="100%">
			<tr>
				<td>
					<table cellspacing="0" cellpadding="0" width="100%" border="0" ID="Table2">
						<tr>
							<td valign="top"><span fckLang="DlgLnkURL">URL</span><BR>
								<input style="WIDTH: 100%" type="text" id="txtURL">
								<table cellspacing="0" cellpadding="0" width="100%" border="0" style="DISPLAY: none" id="tableUpload">
									<tr>
										<form id="frmUpload" enctype="multipart/form-data" method="post" target="UploadWindow">
											<td><span fckLang="DlgLnkUpload">Upload</span><br>
												<input style="WIDTH: 100%" type="file" name="FCKeditor_File" id="FCKeditor_File">
											</td>
									</tr>
									<TR>
										<TD align="right">
											<INPUT id="btnUpload" type="button" fckLang="DlgLnkBtnUpload" value="Send it to the Server" onclick="uploadFile();">
										</TD>
										</FORM>
									</TR>
								</table>
							</td>
							<TD width="10">&nbsp;&nbsp;&nbsp;
							</TD>
							<TD valign="top" width="100">
								<INPUT style="WIDTH: 100%" onclick="ok();" type="button" fckLang="DlgBtnOK" value="Ok">
								<BR>
								<INPUT type="button" style="WIDTH: 100%" fckLang="DlgBtnCancel" value="Cancel" onclick="cancel();">
								<BR>
								<INPUT type="button" style="DISPLAY: none; WIDTH: 100%" fckLang="DlgLnkBtnBrowse" value="Browse Server" onclick="browserServer();"
									id="btnBrowse">
							</TD>
						</tr>
					</table>
					<HR width="100%" color="#000000" size="2">
					<TABLE cellSpacing="0" cellPadding="0" width="100%" border="0">
						<TR>
							<TD><span fckLang="DlgLnkTarget">Target</span><BR>
								<SELECT id="selTarget">
									<OPTION value="" fckLang="DlgLnkTargetNotSet" selected>&lt;Not set&gt;</OPTION>
									<OPTION value="_blank" fckLang="DlgLnkTargetBlank">New Window (_blank)</OPTION>
									<OPTION value="_parent" fckLang="DlgLnkTargetParent">Parent Window (_parent)</OPTION>
									<OPTION value="_self" fckLang="DlgLnkTargetSelf">Same Window (_self)</OPTION>
									<OPTION value="_top" fckLang="DlgLnkTargetTop">Topmost Window (_top)</OPTION>
								</SELECT>
							</TD>
							<TD width="100%"><span fckLang="DlgLnkTitle">Title</span><br>
								<INPUT id="txtTitle" style="WIDTH: 100%" type="text">
							</TD>
						</TR>
					</TABLE>
				</td>
			</tr>
		</table>
		<SCRIPT language="javascript">
<!--
	if (bCanUpload)
	{
		tableUpload.style.display = "block" ;
		frmUpload.action = sUploadURL ;
	}
	
	if (bCanBrowse)
		btnBrowse.style.display = "block" ;
//-->
</SCRIPT>
	</body>
</html>
